package com.abc.service.impl;

import com.abc.entity.Admin;
import com.abc.mapper.AdminMapper;
import com.abc.service.IAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2024-12-25
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements IAdminService {
    @Override
    public boolean addAdmin(Admin admin) throws Exception {
        // 验证管理员用户名是否已存在
        Admin existAdmin = this.lambdaQuery().eq(Admin::getAdminName, admin.getAdminName()).one();
        if (existAdmin != null) {
            throw new Exception("管理员用户名已存在");
        }
        // 密码加密存储
        admin.setPassword(DigestUtils.md5Hex(admin.getPassword()));
        return this.save(admin);
    }
}
